//
//  LCWEmotionPageView.swift
//  MyWB
//
//  Created by 李成万 on 16/7/4.
//  Copyright © 2016年 李成万. All rights reserved.
//

import UIKit



class LCWEmotionPageView: UICollectionView {

    let LCWEmotionPageViewId = "LCWEmotionPageViewId"
    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        backgroundColor = RGB(237, green: 237, blue: 237)
        registerClass(LCWPageViewCell.self, forCellWithReuseIdentifier: LCWEmotionPageViewId)
        dataSource = self
        
        let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
        
        flowLayout.minimumInteritemSpacing = 0
        flowLayout.minimumLineSpacing = 0
        flowLayout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        
        flowLayout.scrollDirection = .Horizontal
    }
}

extension LCWEmotionPageView : UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return LCWEmotionTools.sharedTools.emotionss.count
    }
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return LCWEmotionTools.sharedTools.emotionss[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(LCWEmotionPageViewId, forIndexPath: indexPath) as! LCWPageViewCell
        
//        cell.backgroundColor = randomColor()
        cell.indexPath = indexPath
        
        cell.emotions = LCWEmotionTools.sharedTools.emotionss[indexPath.section][indexPath.item]
        return cell
    }
}
